<?php include "view/nav.php" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>收集数据查看</title>
    <link rel="stylesheet" href="view/static/theme.css" type="text/css">
</head>
<div class="header">
    <h3>收集数据查看</h3>
    <?php echo $nav; ?>
</div>
<div class="main-content">
    <div class="data-content">
        <b>IBeacon数据</b>
        <hr>
        <?php
        require "config.php";

        function readLastLinesOfFile($filePath, $lines = 10)
        {
//            echo "<h3> 文件位置: " . $filePath . "</h3>";
            //global $fsize;
            $handle = fopen($filePath, "r");
            if (!$handle) {
                return array();
            }
            $linecounter = $lines;
            $pos = -2;
            $beginning = false;
            $text = array();
            while ($linecounter > 0) {
                $t = " ";
                while ($t != "\n") {
                    if (fseek($handle, $pos, SEEK_END) == -1) {
                        $beginning = true;
                        break;
                    }
                    $t = fgetc($handle);
                    $pos--;
                }
                $linecounter--;
                if ($beginning) {
                    rewind($handle);
                }
                $text[$lines - $linecounter - 1] = str_replace(array("\r", "\n"), '', fgets($handle));
                if ($beginning) {
                    break;
                }
            }
            fclose($handle);
            return array_reverse($text);
        }


        //        $client_file_path = './data/client_data.txt';
        date_default_timezone_set('PRC');
        $client_file_path = './data/ibeacon_data.txt';
        if(file_exists($client_file_path))
        {
            $content_arr = readLastLinesOfFile($client_file_path, 200);

            $content_arr = array_reverse($content_arr);

            $content_str = '';
            foreach($content_arr as $item)
            {
                $item_arr = explode(chr(9), $item);
                $item_html = implode("&nbsp;&nbsp;&nbsp;&nbsp;", $item_arr);
                $content_str .= $item_html.'</br>';
            }

            echo $content_str;
        }
        else
        {
            echo '没有数据!';
        }
        ?>
    </div>

</div>
<body>
</body>
<script type="text/javascript" src="//cdn.bootcss.com/jquery/2.2.1/jquery.js"></script>
<script type="text/javascript">

</script>
</html>